from jili.pos.module import base
from uuid import uuid1
def getorderid(self):
    return uuid1().hex
class order(base):
    def __init__(self,obj,bs,openclose,price,qty,marketcode,timekey=None,orderid=""):
        super(order, self).__init__()
        self.obj=obj
        self.bs=bs
        self.openclose=openclose
        self.price=price
        self.qty=qty
        self.marketcode=marketcode
        self.timekey=timekey
        if orderid=="":
            self.orderid=getorderid()
        else:
            self.orderid=orderid
class workingorder(base):
    def __init__(self,obj="",bs="",openclose="",price=0,qty=1,marketcode="",workingqty=0,timekey=None,orderid=""):
        super(workingorder, self).__init__()
        self.obj=obj
        self.bs=bs
        self.openclose=openclose
        self.price=price
        self.qty=qty
        self.workingqty = workingqty
        self.marketcode=marketcode
        self.timekey=timekey
        self.date=""
        self.time=""
        self.orderid=orderid
class orderdetail(base):
    def __init__(self,
                 obj="",
                 bs="",
                 openclose="",
                 price=0,
                 qty=0,
                 marketcode="",
                 workingqty=0,
                 tradedqty=0,
                 cancelqty=0,
                 timekey=None,
                 orderid="",
                 date="",
                 time="",
                 updatetime="",
                 status="",
                 tax=0,
                 tradeid="",
                 amount=0,
                 tradeamount=0,
                 cancelamount=0,
                 tradedprice=0
                 ):
        super(orderdetail, self).__init__()
        self.obj=obj
        self.bs=bs
        self.openclose=openclose
        self.price=price
        self.qty=qty
        self.workingqty = workingqty
        self.tradedqty = tradedqty
        self.cancelqty=cancelqty
        self.tradedprice=tradedprice
        self.marketcode = marketcode
        self.timekey = timekey
        self.date = date
        self.time = time
        self.updatetime = updatetime
        self.tardeid=tradeid
        if tradeid=="":
            self.tardeidlist=[]
        else:
            self.tardeidlist=[tradeid]
        self.orderid = orderid
        self.status = status
        self.tax=tax
        self.amount=amount
        self.tradedamount=tradeamount
        self.cancelamount=cancelamount
    def update_trade(self,t):
        tradeid=t.tradeid
        if tradeid not in self.tardeidlist:
            self.tardeidlist.append(tradeid)
class tradedetail(base):
    def __init__(self,
                 obj="",
                 bs="",
                 openclose="",
                 price=0,
                 qty=0,
                 marketcode="",
                 tradedqty=0,
                 timekey=None,
                 orderid="",
                 date="",
                 time="",
                 updatetime="",
                 tradeid="",
                 tax=0,
                 tradedamount=0,
                 tradedprice=0
                 ):
        super(tradedetail, self).__init__()
        self.obj=obj
        self.bs=bs
        self.openclose=openclose
        self.price=price
        self.qty=qty
        self.marketcode=marketcode
        self.timekey=timekey
        self.orderid=orderid
        self.tradeid=tradeid
        self.tradedprice=tradedprice
        self.tradedqty = tradedqty
        self.date = date
        self.time = time
        self.updatetime = updatetime
        self.tax = tax
        self.tradedamount = tradedamount